<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

</body>
<script src="question/q-2.js"></script>
<script>
    // mix(A, B);

    // function f(a, b, c) {
    //     console.log(a + b + c)
    // }
    //
    // funcA(f)(0)(1)(2)();
    // funcA(f)(4)(1)(2)();
    //
    // f(0, 1, 3);

    var obj = {
        a: 1,
        b: function (a, b) {
            console.log(this.a + a + b)
        }
    };

    funcB(obj.b)(obj, 2, 3);
    obj.b(2, 3);


    var obj = {
        b: 1
    };

    function fn(obj) {
        obj.a = 2;
        obj = {c: 3};
        obj.b = 3;
    }

    fn(obj);

    console.log(obj);

    function fn1(obj) {
        a = 1;
        with (obj) {
            a = 2;
        }
        console.log(a);
    }

    fn1(obj);

    var foo = function bar() {
        console.log('z')
    };
    foo();

    function fo1() {
        fo1 = 1;
        console.log(fo1);
    }

    var fo1 = 0;

    // fo1();

    var arr1 = [1, 2];
    var arr2 = [...arr1];
    var arr3 = arr1;
    var arr4 = '123';
    arr4[0] = '4';

    arr1.push(3);

    console.log(arr1, arr2, arr3, arr4[0]);

    var tom = {
        name: 'tom',
        age: [],
        sex: {
            a: ''
        }
    };
    var jack = tom;
    jack.name = 'jack';
    jack.age.push(0);
    tom[Symbol('c')] = 2;
    console.log(tom);

    var a = new function () {
        return 1;
    };
    console.log(a);

    var test1 = 0 && 1;
    var test2 = 1 && 2;
    var test3 = 1 && 0;
    var test4 = 0 && 0;

    var test5 = 0 || 1;
    var test6 = 1 || 1;
    var test7 = 1 || 0;
    var test8 = 0 || 0;

    console.log(test2);


    let e = [{name: 'a', age: 10}, {name: 'b', age: 5}];
    let nArr = e.concat(e);
    nArr[0].name = 'c';
    console.log(nArr);


    // console.log('promise 0');

    var p1 = new Promise((resolve) => {
        console.log('promise 1');
        setTimeout(() => {
            console.log('promise 2');
            resolve('promise 3')
        }, 1000)
    });

    var date = Date.now();

    console.log('promise 4');
    p1.then((val) => {
        console.log(val, Date.now() - date, 'first');
        // console.log(val, Date.now() - date);
        // throw new Error('error');
        return new Error('error');
        // return Promise.reject(new Error('error'));
    }).then(val => {
        console.log('then', val)
    }).catch(val => {
        console.log('catch', val)
    });

    p1.then(val => {
        console.log(val, Date.now() - date, 'second');
    }).catch(val => {
        console.log('catch', val)
    });


</script>
</html>